﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Xml;

public class Logger : IDisposable
{
    private bool bDisposed;
    private Dictionary<string, List<Logger>> dicLogger;

    private string sEventSource = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
    public string EventSource
    {
        get
        {
            return sEventSource;
        }
        set
        {
            sEventSource = value;
        }
    }

    public class LogDetails
    {
        public enum InitiatedLogs : int
        {
            file = 1,
            database = 2,
            eventlog = 4
        }
        public InitiatedLogs oLogTypes;

        //file
        public class LogFile
        {
            private string sFileName;
            private string sFileDir;
            private bool bDatePattern;
            private char cPatternDelim;

            public string FileName
            {
                get
                {
                    return sFileName;
                }
                set
                {
                    sFileName = value;
                }
            }

            public string FilePath
            {
                get
                {
                    return sFileDir;
                }
                set
                {
                    sFileDir = value;
                }
            }

            public string FileFullName
            {
                get
                {
                    return sFileDir + sFileName;
                }
            }

            public bool UseDatePattern
            {
                get
                {
                    return bDatePattern;
                }
                set
                {
                    bDatePattern = value;
                }
            }

            public char PatternDelimiter
            {
                get
                {
                    return cPatternDelim;
                }
                set
                {
                    cPatternDelim = value;
                }
            }
        }
        public LogFile oLogFile = new LogFile();


        //database
        public class DBLog
        {
            private string sDBTableName;
            private string sDBConnectionString;
            private string sEventSourceColumn;
            private string sEventTypeColumn;
            private string sEventMessageColumn;

            public string TableName
            {
                get
                {
                    return sDBTableName;
                }
                set
                {
                    sDBTableName = value;
                }
            }
            public string ConnectionString
            {
                get
                {
                    return sDBConnectionString;
                }
                set
                {
                    sDBConnectionString = value;
                }
            }
            public string EventSourceColumn
            {
                get
                {
                    return sEventSourceColumn;
                }
                set
                {
                    sEventSourceColumn = value;
                }
            }
            public string EventTypeColumn
            {
                get
                {
                    return sEventTypeColumn;
                }
                set
                {
                    sEventTypeColumn = value;
                }
            }
            public string EventMessageColumn
            {
                get
                {
                    return sEventMessageColumn;
                }
                set
                {
                    sEventMessageColumn = value;
                }
            }

            public SqlConnection sqlConOutDB = new SqlConnection();

            public DBLog()
            {
                ;
            }
        }
        public DBLog oDBLog = new DBLog();

        //eventlog
        protected EventLog oEventLog;
        public class Entry
        {
            public enum Severity
            {
                Verbose = 1,
                Info = 2,
                Warning = 3,
                Error = 4,
                Fatal = 5
            };

            private Severity enSeverityLevel;
            private string sMessage;
            private int iEventId;

            public Severity SeverityLevel
            {
                get
                {
                    return enSeverityLevel;
                }
                set
                {
                    enSeverityLevel = value;
                }
            }

            public string Message
            {
                get
                {
                    return sMessage;
                }
                set
                {
                    sMessage = value;
                }
            }

            public int EventID
            {
                get
                {
                    return iEventId;
                }
                set
                {
                    iEventId = value;
                }
            }
        }
        public Entry oEntry = new Entry();

        public enum MsgType
        {
            Verbose = 1,
            Info = 2,
            Warning = 3,
            Error = 4
        }
        public MsgType oMsgType = new MsgType();

        public LogDetails()
        {
            ;
        }
    }
    private LogDetails oLogDetails = new LogDetails();

    #region Constructors
    public Logger()
    {
        this.bDisposed = false;
        ;
    }

    public Logger(string sLoggerConfiguration)
    {
        try
        {
            this.bDisposed = false;
            this.InitiateLogger(sLoggerConfiguration);
        }
        catch (Exception ex)
        {
            this.WriteEventLogMessage(LogDetails.Entry.Severity.Error, String.Format("{0}::{1}", new StackTrace(true).GetFrame(0).GetMethod().Name.ToString(), ex.Message));
        }
    }

    public Logger(Logger.LogDetails.MsgType oType, string sFileName, string sFilePath, bool bUsePattern)
    {
        try
        {
            this.bDisposed = false;
            this.oLogDetails.oMsgType = oType;
            this.InitiateFileLog(this.GenFileLogDetails(sFileName, sFileName, bUsePattern));
        }
        catch (Exception ex)
        {
            this.WriteEventLogMessage(LogDetails.Entry.Severity.Error, String.Format("{0}::{1}", new StackTrace(true).GetFrame(0).GetMethod().Name.ToString(), ex.Message));
        }
    }

    public Logger(Logger.LogDetails.MsgType oType, string sSqlConnectionString, string sTableName, string[] aDestinationColumns)
    {
        try
        {
            this.bDisposed = false;
            this.oLogDetails.oMsgType = oType;
            this.InitiateDatabaseLog(this.GenDatabaseLogDetails(sSqlConnectionString, sTableName, aDestinationColumns));
        }
        catch (Exception ex)
        {
            this.WriteEventLogMessage(LogDetails.Entry.Severity.Error, String.Format("{0}::{1}", new StackTrace(true).GetFrame(0).GetMethod().Name.ToString(), ex.Message));
        }
    }

    public Logger(Logger.LogDetails.MsgType oType, int iEventID, string sEventLog)
    {
        try
        {
            this.bDisposed = false;
            this.oLogDetails.oMsgType = oType;
            this.InitiateEventLog(this.GenEventLogDetails(iEventID, sEventLog));
        }
        catch (Exception ex)
        {
            this.WriteEventLogMessage(LogDetails.Entry.Severity.Error, String.Format("{0}::{1}", new StackTrace(true).GetFrame(0).GetMethod().Name.ToString(), ex.Message));
        }
    }
    #endregion

    #region Public Methods
    public void WriteToLog(string sMessage)
    {
        try
        {
            if (Convert.ToBoolean(this.oLogDetails.oLogTypes & LogDetails.InitiatedLogs.file))
            {
                this.WriteFileLogMessage(this.CreateFileMessage(sMessage));
            }
            else if (Convert.ToBoolean(this.oLogDetails.oLogTypes & LogDetails.InitiatedLogs.database))
            {
                this.WriteDatabaseLogMessage(this.CreateDatabaseMessage(sMessage));
            }
            else if (Convert.ToBoolean(this.oLogDetails.oLogTypes & LogDetails.InitiatedLogs.eventlog))
            {
                this.WriteEventLogMessage(this.CreateEventMessage(sMessage));
            }
        }
        catch (Exception ex)
        {
            throw new Exception(String.Format("{0}::{1}", new StackTrace(true).GetFrame(0).GetMethod().Name.ToString(), ex.Message));
        }
    }

    public void WriteToLog(string sMessage, Logger.LogDetails.MsgType enMsgType)
    {
        try
        {
            if (dicLogger.ContainsKey(enMsgType.ToString()))
            {
                foreach (Logger oLogger in this.dicLogger[enMsgType.ToString()])
                {
                    oLogger.WriteToLog(sMessage);
                }
            }
        }
        catch (Exception ex)
        {
            this.WriteEventLogMessage(LogDetails.Entry.Severity.Error, String.Format("{0}::{1}", new StackTrace(true).GetFrame(0).GetMethod().Name.ToString(), ex.Message));
        }
    }
    #endregion

    #region Private Methods
    private void WriteFileLogMessage(string sMessage)
    {
        try
        {
            if (this.oLogDetails.oLogFile.UseDatePattern) //update file name with current date & time
            {
                string sDatePattern = this.oLogDetails.oLogFile.FileName.Split(this.oLogDetails.oLogFile.PatternDelimiter)[1];
                this.oLogDetails.oLogFile.FileName = String.Format("{0}{1}{2}",
                        this.oLogDetails.oLogFile.FileName.Split(this.oLogDetails.oLogFile.PatternDelimiter)[0],
                        DateTime.Now.ToString(this.oLogDetails.oLogFile.FileName.Split(this.oLogDetails.oLogFile.PatternDelimiter)[1]),
                        this.oLogDetails.oLogFile.FileName.Split(this.oLogDetails.oLogFile.PatternDelimiter)[2]);
            }
            this.oLogDetails.oLogFile.UseDatePattern = false;
            using (StreamWriter swFile = new StreamWriter(this.oLogDetails.oLogFile.FileFullName, true, Encoding.UTF8))
            {
                swFile.WriteLine(sMessage);
                swFile.Close();
            }
        }
        catch (Exception ex)
        {
            this.WriteEventLogMessage(LogDetails.Entry.Severity.Error, String.Format("{0}::{1}", new StackTrace(true).GetFrame(0).GetMethod().Name.ToString(), ex.Message));
        }
    }

    private void WriteDatabaseLogMessage(string sSqlCommand)
    {
        try
        {
            using (SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sSqlCommand, this.oLogDetails.oDBLog.sqlConOutDB))
            {
                sqlDataAdapter.SelectCommand.ExecuteNonQuery();
            }
        }
        catch (Exception ex)
        {
            this.WriteEventLogMessage(LogDetails.Entry.Severity.Error, String.Format("{0}::{1}", new StackTrace(true).GetFrame(0).GetMethod().Name.ToString(), ex.Message));
        }
    }

    private void WriteEventLogMessage(LogDetails.Entry objEntry)
    {
        try
        {
            using (EventLog oEventLog = new System.Diagnostics.EventLog("Application", ".", System.Reflection.Assembly.GetExecutingAssembly().GetName().Name))
            {

                if (objEntry.SeverityLevel == LogDetails.Entry.Severity.Error)
                {
                    oEventLog.WriteEntry(objEntry.Message, EventLogEntryType.Error, objEntry.EventID);
                }
                else if (objEntry.SeverityLevel == LogDetails.Entry.Severity.Warning)
                {
                    oEventLog.WriteEntry(objEntry.Message, EventLogEntryType.Warning, objEntry.EventID);
                }
                else
                {
                    oEventLog.WriteEntry(objEntry.Message, EventLogEntryType.Information, objEntry.EventID);
                }
            }
        }
        catch (Exception ex)
        {
            using (EventLog oEventLog = new System.Diagnostics.EventLog("Application", ".", System.Reflection.Assembly.GetExecutingAssembly().GetName().Name))
            {
                oEventLog.WriteEntry(String.Format("{0}::{1}", new StackTrace(true).GetFrame(0).GetMethod().Name.ToString(), ex.Message), EventLogEntryType.Error, 2103);
            }
        }
    }

    private void WriteEventLogMessage(LogDetails.Entry.Severity enSeverity, string sMessage)
    {
        try
        {
            LogDetails.Entry objEntry = new LogDetails.Entry();
            objEntry.EventID = 2103;
            objEntry.Message = sMessage;
            objEntry.SeverityLevel = enSeverity;
            WriteEventLogMessage(objEntry);
        }
        catch (Exception ex)
        {
            using (EventLog oEventLog = new System.Diagnostics.EventLog("Application", ".", System.Reflection.Assembly.GetExecutingAssembly().GetName().Name))
            {
                oEventLog.WriteEntry(String.Format("{0}::{1}", new StackTrace(true).GetFrame(0).GetMethod().Name.ToString(), ex.Message), EventLogEntryType.Error, 2103);
            }
        }
    }

    private string CreateFileMessage(string sMessage)
    {
        try
        {
            string sDelimiter = "\t";
            char cMsgType;

            switch (this.oLogDetails.oMsgType)
            {
                case LogDetails.MsgType.Info:
                    cMsgType = 'I';
                    break;
                case LogDetails.MsgType.Verbose:
                    cMsgType = 'V';
                    break;
                case LogDetails.MsgType.Error:
                    cMsgType = 'E';
                    break;
                case LogDetails.MsgType.Warning:
                    cMsgType = 'W';
                    break;
                default:
                    cMsgType = 'X';
                    break;
            }

            string sString = String.Format("{0}{2}{1}", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), cMsgType, sDelimiter);

            return String.Format("{0}{2}{1}", sString, sMessage, sDelimiter);
        }
        catch (Exception ex)
        {
            throw new Exception(String.Format("{0}::{1}", new StackTrace(true).GetFrame(0).GetMethod().Name.ToString(), ex.Message));
        }
    }

    private string CreateDatabaseMessage(string sMessage)
    {
        try
        {
            string sSQLString = String.Format(@"
			INSERT INTO {0}
				([{1}],[{2}],[{3}])
			SELECT
				'{4}','{5}','{6}'",
                this.oLogDetails.oDBLog.TableName,
                this.oLogDetails.oDBLog.EventSourceColumn, this.oLogDetails.oDBLog.EventMessageColumn, this.oLogDetails.oDBLog.EventTypeColumn,
                String.Format("{0}@{1}", this.EventSource, System.Net.Dns.GetHostName()), sMessage.Replace(@"'", @"''"), this.oLogDetails.oMsgType
                );

            return sSQLString;
        }
        catch (Exception ex)
        {
            throw new Exception(String.Format("{0}::{1}", new StackTrace(true).GetFrame(0).GetMethod().Name.ToString(), ex.Message));
        }
    }

    private LogDetails.Entry CreateEventMessage(string sMessage)
    {
        try
        {
            LogDetails.Entry oEntry = new LogDetails.Entry();

            oEntry.EventID = this.oLogDetails.oEntry.EventID;
            switch (this.oLogDetails.oMsgType)
            {
                case LogDetails.MsgType.Verbose:
                    oEntry.SeverityLevel = LogDetails.Entry.Severity.Verbose;
                    break;
                case LogDetails.MsgType.Info:
                    oEntry.SeverityLevel = LogDetails.Entry.Severity.Info;
                    break;
                case LogDetails.MsgType.Warning:
                    oEntry.SeverityLevel = LogDetails.Entry.Severity.Warning;
                    break;
                case LogDetails.MsgType.Error:
                    oEntry.SeverityLevel = LogDetails.Entry.Severity.Error;
                    break;
            }
            oEntry.Message = sMessage;

            return oEntry;
        }
        catch (Exception ex)
        {
            throw new Exception(String.Format("{0}::{1}", new StackTrace(true).GetFrame(0).GetMethod().Name.ToString(), ex.Message));
        }
    }

    private void InitiateFileLog(LogDetails oLogDet)
    {
        try
        {
            this.oLogDetails = oLogDet;
            if (!Directory.Exists(oLogDetails.oLogFile.FilePath))
            {
                Directory.CreateDirectory(oLogDetails.oLogFile.FilePath);
            }
            oLogDetails.oLogTypes |= LogDetails.InitiatedLogs.file;
        }
        catch (Exception ex)
        {
            throw new Exception(String.Format("{0}::{1}", new StackTrace(true).GetFrame(0).GetMethod().Name.ToString(), ex.Message));
        }
    }

    private void InitiateDatabaseLog(LogDetails oLogDet)
    {
        try
        {
            this.oLogDetails = oLogDet;
            this.oLogDetails.oDBLog.sqlConOutDB.ConnectionString = oLogDetails.oDBLog.ConnectionString;
            this.oLogDetails.oDBLog.sqlConOutDB.Open();

            this.oLogDetails.oLogTypes |= LogDetails.InitiatedLogs.database;
        }

        catch (Exception ex)
        {
            throw new Exception(String.Format("{0}::{1}", new StackTrace(true).GetFrame(0).GetMethod().Name.ToString(), ex.Message));
        }
    }

    private void InitiateEventLog(LogDetails oLogDet)
    {
        try
        {
            this.oLogDetails = oLogDet;
            this.oLogDetails.oLogTypes |= LogDetails.InitiatedLogs.eventlog;
        }
        catch (Exception ex)
        {
            throw new Exception(String.Format("{0}::{1}", new StackTrace(true).GetFrame(0).GetMethod().Name.ToString(), ex.Message));
        }
    }

    private void InitiateLogger(string sLoggerConf)
    {
        try
        {
            //create a new dicLogger
            this.dicLogger = new Dictionary<string, List<Logger>>();

            string[] aLoggerConf = sLoggerConf.Split(';');
            foreach (string sLogMethodID in aLoggerConf)
            {
                string[] aLogMethodID = sLogMethodID.Split(':');
                if (aLogMethodID[0].Equals("info", StringComparison.OrdinalIgnoreCase))
                {
                    string[] aLogDefinitions = ConfigurationManager.AppSettings[aLogMethodID[1]].ToString().Split(';');
                    foreach (string sLogDefID in aLogDefinitions)
                    {
                        this.InitiateDicLogger(sLogDefID.Split(':'), LogDetails.MsgType.Info);
                    }
                }
                else if (aLogMethodID[0].Equals("verbose", StringComparison.OrdinalIgnoreCase))
                {
                    string[] aLogDefinitions = ConfigurationManager.AppSettings[aLogMethodID[1]].ToString().Split(';');
                    foreach (string sLogDefID in aLogDefinitions)
                    {
                        this.InitiateDicLogger(sLogDefID.Split(':'), LogDetails.MsgType.Verbose);
                    }
                }
                else if (aLogMethodID[0].Equals("error", StringComparison.OrdinalIgnoreCase))
                {
                    string[] aLogDefinitions = ConfigurationManager.AppSettings[aLogMethodID[1]].ToString().Split(';');
                    foreach (string sLogDefID in aLogDefinitions)
                    {
                        this.InitiateDicLogger(sLogDefID.Split(':'), LogDetails.MsgType.Error);
                    }
                }
                else if (aLogMethodID[0].Equals("warning", StringComparison.OrdinalIgnoreCase))
                {
                    string[] aLogDefinitions = ConfigurationManager.AppSettings[aLogMethodID[1]].ToString().Split(';');
                    foreach (string sLogDefID in aLogDefinitions)
                    {
                        this.InitiateDicLogger(sLogDefID.Split(':'), LogDetails.MsgType.Warning);
                    }
                }
            }

        }
        catch (Exception ex)
        {
            throw new Exception(String.Format("{0}::{1}", new StackTrace(true).GetFrame(0).GetMethod().Name.ToString(), ex.Message));
        }
    }

    private void InitiateDicLogger(string[] aLogDefinition, LogDetails.MsgType enMsgType)
    {
        try
        {
            if (aLogDefinition.Length > 1)
            {
                Logger oLogger = new Logger();
                oLogger.oLogDetails = this.ReadLogConfig(aLogDefinition);
                if (Convert.ToBoolean(oLogger.oLogDetails.oLogTypes & LogDetails.InitiatedLogs.file))
                {
                    oLogger.InitiateFileLog(oLogger.oLogDetails);
                }
                else if (Convert.ToBoolean(oLogger.oLogDetails.oLogTypes & LogDetails.InitiatedLogs.database))
                {
                    oLogger.InitiateDatabaseLog(oLogger.oLogDetails);
                }
                else if (Convert.ToBoolean(oLogger.oLogDetails.oLogTypes & LogDetails.InitiatedLogs.eventlog))
                {
                    oLogger.InitiateEventLog(oLogger.oLogDetails);
                }
                oLogger.oLogDetails.oMsgType = enMsgType;
                if (!dicLogger.ContainsKey(oLogger.oLogDetails.oMsgType.ToString()))
                {
                    dicLogger.Add(enMsgType.ToString(), new List<Logger>());
                }
                dicLogger[enMsgType.ToString()].Add(oLogger);
            }
        }
        catch (Exception ex)
        {
            throw new Exception(String.Format("{0}::{1}", new StackTrace(true).GetFrame(0).GetMethod().Name.ToString(), ex.Message));
        }
    }

    private LogDetails GenFileLogDetails(string sFileName, string sFilePath, bool bUsePattern)
    {
        try
        {
            LogDetails oLogDet = new LogDetails();
            oLogDet.oLogTypes = LogDetails.InitiatedLogs.file;
            oLogDet.oLogFile.FileName = sFileName;
            if (sFilePath.Equals("."))
            {
                sFilePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
                sFilePath = sFilePath.Remove(sFilePath.LastIndexOf("\\"));
            }
            oLogDet.oLogFile.FilePath = sFilePath.EndsWith("\\") ? sFilePath : sFilePath + "\\";

            if (bUsePattern)
            {
                oLogDet.oLogFile.UseDatePattern = true;
                oLogDet.oLogFile.PatternDelimiter = (char)0x25;
            }
            return oLogDet;
        }
        catch (Exception ex)
        {
            throw new Exception(String.Format("{0}::{1}", new StackTrace(true).GetFrame(0).GetMethod().Name.ToString(), ex.Message));
        }
    }

    private LogDetails GenDatabaseLogDetails(string sSqlConnectionString, string sTableName, string[] aSpecColumns)
    {
        try
        {
            const int EVENT_VAR = 0;
            const int TABLE_COL = 1;

            string sEvSrcCol = "msg_source";
            string sEvTypeCol = "msg_type";
            string sEvMsgCol = "msg_body";

            LogDetails oLogDet = new LogDetails();

            oLogDet.oLogTypes = LogDetails.InitiatedLogs.database;
            oLogDet.oDBLog.ConnectionString = sSqlConnectionString;
            oLogDet.oDBLog.TableName = sTableName;

            foreach (string sDestCol in aSpecColumns)
            {
                string[] aDestColDet = sDestCol.Split('=');
                if (aDestColDet[EVENT_VAR].Equals(sEvSrcCol, StringComparison.OrdinalIgnoreCase))
                {
                    oLogDet.oDBLog.EventSourceColumn = aDestColDet[TABLE_COL];
                }
                else if (aDestColDet[EVENT_VAR].Equals(sEvTypeCol, StringComparison.OrdinalIgnoreCase))
                {
                    oLogDet.oDBLog.EventTypeColumn = aDestColDet[TABLE_COL];
                }
                else if (aDestColDet[EVENT_VAR].Equals(sEvMsgCol, StringComparison.OrdinalIgnoreCase))
                {
                    oLogDet.oDBLog.EventMessageColumn = aDestColDet[TABLE_COL];
                }
            }
            return oLogDet;

        }
        catch (Exception ex)
        {
            throw new Exception(String.Format("{0}::{1}", new StackTrace(true).GetFrame(0).GetMethod().Name.ToString(), ex.Message));
        }
    }

    private LogDetails GenEventLogDetails(int iEventID, string sEventLog)
    {
        try
        {
            LogDetails oLogDet = new LogDetails();
            oLogDet.oLogTypes = LogDetails.InitiatedLogs.eventlog;
            oLogDet.oEntry.EventID = iEventID;
            return oLogDet;
        }
        catch (Exception ex)
        {
            throw new Exception(String.Format("{0}::{1}", new StackTrace(true).GetFrame(0).GetMethod().Name.ToString(), ex.Message));
        }
    }

    private LogDetails ReadLogConfig(string[] aLogDef)
    {
        try
        {
            LogDetails oLogDet = new LogDetails();

            if (aLogDef[0].Equals("fl", StringComparison.OrdinalIgnoreCase))
            {
                const string PARAMETERS = "_Params";

                bool bDatePattern = false;

                string sFileFullName = ConfigurationManager.AppSettings[aLogDef[1]].ToString();
                string sParameters = ConfigurationManager.AppSettings[aLogDef[1] + PARAMETERS].ToString();

                if (sParameters != null && sParameters != String.Empty) //parameters are optional
                {
                    foreach (string sParam in sParameters.Split(';'))
                    {
                        if (sParam.Equals("date_pattern", StringComparison.OrdinalIgnoreCase))
                        {
                            bDatePattern = true;
                        }
                    }
                }
                string sFileName = sFileFullName.Remove(0, sFileFullName.LastIndexOf('\\') + 1);
                string sFilePath = sFileFullName.Substring(0, sFileFullName.LastIndexOf('\\'));
                return this.GenFileLogDetails(sFileName, sFilePath, bDatePattern);
            }
            else if (aLogDef[0].Equals("db", StringComparison.OrdinalIgnoreCase))
            {
                const string TABLE_SUFFIX = "_Table";
                const string COLUMN_SUFFIX = "_Columns";

                string sConnStringName = ConfigurationManager.AppSettings[aLogDef[1]].ToString();

                return this.GenDatabaseLogDetails(ConfigurationManager.ConnectionStrings[sConnStringName].ToString(),
                                                    ConfigurationManager.AppSettings[aLogDef[1] + TABLE_SUFFIX].ToString(),
                                                    ConfigurationManager.AppSettings[aLogDef[1] + COLUMN_SUFFIX].ToString().Split(';'));
            }

            else if (aLogDef[0].Equals("ev", StringComparison.OrdinalIgnoreCase))
            {
                const string EVENT_ID = "_EventID";

                int iEventID = Convert.ToInt32(ConfigurationManager.AppSettings[aLogDef[1] + EVENT_ID]);
                return this.GenEventLogDetails(iEventID, "varNotSupp");
            }
            return null;
        }

        catch (Exception ex)
        {
            throw new Exception(String.Format("{0}::{1}", new StackTrace(true).GetFrame(0).GetMethod().Name.ToString(), ex.Message));
        }
    }
    #endregion

    //dispose
    #region IDisposable Members
    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }

    protected virtual void Dispose(bool bDisposing)
    {
        if (!this.bDisposed)
        {
            if (bDisposing)
            {
                this.oLogDetails.oDBLog.sqlConOutDB.Close();
                this.oLogDetails.oDBLog.sqlConOutDB.Dispose();
                if (dicLogger != null)
                {
                    foreach (List<Logger> lLogCollections in dicLogger.Values)
                    {
                        foreach (Logger oLogToDie in lLogCollections)
                        {
                            oLogToDie.Dispose();
                        }
                    }
                    this.dicLogger = null;
                }
            }

            this.bDisposed = true;
        }
    }

    #endregion
}
